<!--
 * @Author: lixiang
 * @Date: 2021-11-03 16:26:31
 * @Description: 
-->
<template>
  <el-submenu v-if="menu.children && menu.children.length >= 1" :date-index="menu.menuId + ''" :index="menu.menuId + ''">
    <template slot="title">
      <i :class="`el-icon-${menu.menuIcon}`"></i>
      <span slot="title">{{menu.menuName}}</span>
    </template>
    <MenuTree v-for="item in menu.children" :key="item.menuId" :menu="item"></MenuTree>
  </el-submenu>
  <el-menu-item v-else :data-index="menu.menuId + ''" :index="menu.menuId + ''" @click="handleRoute(menu)">
    <i :class="`el-icon-${menu.menuIcon}`"></i>
    <span slot="title">{{menu.menuName}}</span>
  </el-menu-item>
</template>

<script>
// let chooseData=[];
// let chooseId=[];
import { mapState } from "vuex";

export default {
  name: "MenuTree",
  data(){
    return{
      // chooseData:[],
      // aaa:0,
    }
  },
  props: {
    menu: {
      type: Object,
      required: true
    }
  },
  computed: {
    ...mapState(['menuList']),
  },
  methods: {
    /**
     * 左侧menu点击事件
     */
    handleRoute(menu) {
      let _this = this
      let menuList = _this.menuList
      let list = _this.menuList
      let dataIds = menuList.map(item => item.menuId)
      _this.$store.commit('saveActiveTab',{id:menu.menuId,url:menu.menuUrl})
      if(dataIds.indexOf(menu.menuId) == -1){
       

        list.push(menu)
        _this.$store.commit('saveMenuList',list)
        
        console.log('菜单',dataIds)
      }
     this.$emit('func')
    //  console.log('档期啊menu',menu)
     
      // 通过菜单URL跳转至指定路由
      // this.$router.push('/index/system/menu')
      this.$router.push(menu.menuUrl);
    }
  }
};
</script>